<template>
  <div class="base-container">
    <t-form  ref="form" :data="queryParams" label-width="80" @submit="()=>{this.getList()}" @reset="()=>{this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item name="keyWordList" label="关键词">
            <t-select
              style="width: 340px;"
              v-model="queryParams.keyWordList"
              creatable
              filterable
              multiple
              placeholder="手输支持自定义创建"
              :options="keyWordOptions"
              @create="createKeyWordOptions"
              @change="onKeyWordChange"
            >
            </t-select>
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit"> 查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>

    </t-form>
    <t-table
      rowKey="projectId"
      size="small"
      :data="projectEsModelList"
      :columns="columns"
      hover
    >
      <template #index="{rowIndex}">
        {{ rowIndex + 1 }}
      </template>
      <template #op="{row, rowIndex}">
        <t-button @click="dialog.objId=row.projectId;dialog.open_digest=true"
                  size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    <project-digest-dialog :objId="dialog.objId" :visible.sync="dialog.open_digest"
                           v-if="dialog.open_digest" ></project-digest-dialog>
  </div>
</template>

<script>
import ProjectDigestDialog from "../apply/components/project-digest-dialog.vue";

export default {
  name: "project-similar-index",
  components: {
    ProjectDigestDialog
  },
  data(){
    return {
      dialog: {
        objId: null,
        open_digest: false,
      },
      projectEsModelList: [],
      keyWordOptions: [],
      queryParams: {
        keyWordList: []
      },
      columns: [
        {
          colKey: "index",
          title: "序号",
          align: "center",
          width: 90
        },
        {
          colKey: "projectName",
          title: "项目名称",
          align: "center",
        },
        {
          colKey: "keyWord",
          title: "关键词",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
        }
      ],
    }
  },
  methods: {
    getList(){
      const keyword = this.queryParams.keyWordList.join(";")
      if(keyword){
        this.$api.kjxm.project.getSimilarProjectByName({keyWord: keyword}).then(response => {
          this.projectEsModelList = response.data || [];
        }).catch((e) => {
          this.$message.error(e.toString());
        });
      }
    },
    createKeyWordOptions(value) {
      this.keyWordOptions.push({
        label: `${value}`,
        value,
      });
    },
    onKeyWordChange(val) {
      this.getList()
    },
  }
}
</script>

<style scoped>

</style>
